/**
* @author attilax 1466519819@qq.com
* @version  c0
* Copyright 2013 attilax reserved.
* All content (including but not limited to text, pictures, etc.) have copyright restrictions, the note license.
* all the software source code  copyright belongs to the original owner.
* Creative Commons protocol use please follow the "sign for non-commercial use consistent"; we do not welcome the large-scale duplication, and all rights reserved.
* Commercial sites or unauthorized media may not copy software source code.
**/
 
 


 
package com.mijie.homi.search.dao.mood;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.common.domain.mood.Mood;
import com.mijie.homi.search.api.UserSearchApi;
import com.mijie.homi.search.service.index.clr;
import com.mijie.homi.search.util.JsonValueProcessorImpl;

@Repository
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
public class MoodDao extends IBatisDao {
	
	
	public static void main(String[] args) {
		UserSearchApi.iniProxool();

		MoodDao c = (MoodDao) UserSearchApi.getbean("moodDao");
		// List<Map> li = .selectList("getRecently100", nowId);
		System.out.println(c);
		List<Map> li=c.moodsByIds("1000,2300,2000,3000,4000,490296,490287");
		Map m=li.get(0);
		Object o=m.get("createAt");
		System.out.println(o.getClass());
		System.out.println("size:"+li.size());
		JsonConfig jsonConfig = new JsonConfig(); 
		//使用setExcludes过滤不需要转换的属性
		jsonConfig.setExcludes(new String[] { "POPU_UPDATE_TIME", "POPU_CREATE_TIME","POPT_UPDATE_TIME", "POPT_CREATE_TIME","SYUS_UPDATE_TIME", "SYUS_CREATE_TIME" });
	//	jsonConfig.registerJsonValueProcessor(java.util.Date.class,new JsonValueProcessorImpl());
		jsonConfig.registerJsonValueProcessor(java.sql.Timestamp.class,new JsonValueProcessorImpl());
		jsonConfig.registerJsonValueProcessor(java.sql.Date.class,new JsonValueProcessorImpl());
		
		
		
		
		String s = JSONArray.fromObject(li,jsonConfig).toString(2);
	//	 System.out.println(s);
		System.out.println("f");
		 System.exit(0);
	}
	
	@Autowired
	private SqlSessionTemplate sqlSession;
	
//	sql="select *,u.id uid,e.lastloginat from mood m,user u,userExtInfo e  where  m.userid=u.id and u.id=e.id and m.id in (@ids) order by m.id desc limit 100";
 	@Select("SELECT * FROM mood limit 3") 
	public List moodsByIds(@Param(value="idx") String idx){
		 
	 	//return null;// sqlSession.selectList("");
		// return this.selectList("moodsByIds", ids);
		 return sqlSession.selectList("moodsByIds",  idx);
	}

/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
	public Mood getRecentlyMood(int userId){
		return this.selectOne("getRecentlyMood", userId);
	}
	
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
	public Mood getMoodById(long id){
		return this.selectOne("getMoodById", id);
	}
	
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
	public List<Mood> listRecentlyLoginUserMood(String atleastLastLoginAt,int offset,int limit){
		Map<String,Object> parameter = new HashMap<String,Object>(3);
		parameter.put("atleastLastLoginAt", atleastLastLoginAt);
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return this.selectList("listRecentlyLoginUserMood", parameter);
	}
	
/**
* @author attilax 1466519819@qq.com
* @version  c0
**/
	public boolean haveMoodViewPrivilege(int viewer,long id){
		Map<String,Object> parameter = new HashMap<String,Object>(2);
		parameter.put("id", id);
		parameter.put("viewer", viewer);
		Integer userId =  this.selectInteger("haveMoodViewPrivilege",parameter);
		if(userId!=null && userId==viewer) return true;
		else return false;
	}
}